import java.util.*;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2025-10-08
 * Time: 14:48
 */
public class demo4 {
    public static void main(String[] args) {
        Object locker = new Object();

        Thread t1 = new Thread(() -> {
            try{
                System.out.println("t1 wait之前");
                synchronized(locker){
                    locker.wait();
                }
                System.out.println("t1 wait之后");
            }catch(InterruptedException e){
                e.printStackTrace();
            }
        });

        Thread t2 = new Thread(() -> {
            try{
                System.out.println("t2 wait之前");
                synchronized(locker){
                    locker.wait();
                }
                System.out.println("t2 wait之后");
            }catch(InterruptedException e){
                e.printStackTrace();
            }
        });

        Thread t3 = new Thread(() -> {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入任意内容，激活任一线程");
            sc.next();
            synchronized (locker){
                locker.notify();
            }
            System.out.println("再次输入，再次激活剩余线程");
            sc.next();
            synchronized (locker){
                locker.notify();
            }
        });

        t1.start();
        t2.start();
        t3.start();
    }
}
